package com.estranger.www.enumeration;

import java.util.Objects;

import org.springframework.util.Assert;

import com.estranger.www.strategy.AccountCreateStrategy;
import com.estranger.www.strategy.AccountUpdateStrategy;
import com.estranger.www.strategy.IEventStrategy;

/**
 * @Created by michangtao
 * @Date 2021/11/4 14:07
 * @Description TODO
 */
public enum  EventEnum {

    ACCOUNT_CREATE("create", new AccountCreateStrategy()),
    ACCOUNT_UPDATE("update", new AccountUpdateStrategy());

    public static IEventStrategy matchType(String type){
        Assert.notNull(type,"type can not be null");
        EventEnum[] values = EventEnum.values();
        for (EventEnum eventEnum : values){
            if(Objects.equals(type,eventEnum.getType())){
                return eventEnum.getEventStrategy();
            }
        }
        return null;
    }

    private String type;
    private IEventStrategy eventStrategy;

    EventEnum(String type, IEventStrategy eventStrategy) {
        this.type = type;
        this.eventStrategy = eventStrategy;
    }

    public String getType() {
        return type;
    }

    public void setType(String type) {
        this.type = type;
    }

    public IEventStrategy getEventStrategy() {
        return eventStrategy;
    }

    public void setEventStrategy(IEventStrategy eventStrategy) {
        this.eventStrategy = eventStrategy;
    }
}
